package com.sx.wechat.controller.teacher;

import com.alibaba.fastjson.JSONObject;
import com.sx.core.dao.InformationMapper;
import com.sx.core.model.Information;
import com.sx.core.vo.JsonReaderResponse;
import com.sx.wechat.controller.BaseController;
import com.sx.wechat.security.AuthenticationHolder;
import com.sx.wechat.shiro.InformationPrincipal;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by lihao on 2017/6/29.
 */
@RequestMapping("tc/user")
@RestController
public class UserController extends BaseController {
    @Autowired
    InformationMapper informationMapper;

    @RequestMapping("get_user")
    public JsonReaderResponse list_order() {
        InformationPrincipal principal = AuthenticationHolder.getCurrentInfo();
        return new JsonReaderResponse().addExtra(informationMapper.get(Information.class,principal.getId()));
    }
    @RequestMapping("get_user_by_id")
    public JsonReaderResponse get_user_by_id(String id) {
        return new JsonReaderResponse().addExtra(informationMapper.get(Information.class,id));
    }

    @RequestMapping("update_user")
    public JsonReaderResponse update_user(@RequestBody JSONObject params) {
        InformationPrincipal principal = AuthenticationHolder.getCurrentInfo();
        String sno=params.getString("sno");
        String name=params.getString("name");
        String sex=params.getString("sex");
        String idno=params.getString("idno");
        String email=params.getString("email");
        String mobile=params.getString("mobile");
        Information information=informationMapper.get(Information.class,principal.getId());
        information.setSno(sno);
        information.setName(name);
        information.setSex(sex);
        information.setIdno(idno);
        information.setEmail(email);
        information.setMobile(mobile);
        informationMapper.update(information);
        return new JsonReaderResponse();
    }







}
